import {source} from '../services/component'
const empty=require('is-empty');
export default {
  namespace: 'workLog',
  state: {
    data: {},
    dataDetail:{}
  },
  subscriptions: {
    setup({dispatch, history}) {
      history.listen(({pathname, query}) => {
        if (pathname == "/work/workLog") {
          dispatch({
            type:'getTask',
            payload:{
              code:'workLog',
              pagination:false,
              para:[{key:'art_type',values:[3]},{key:'status',values:[0]}],
            }
          });
        }else if(pathname=='/work/workLog/workDetails'){
          dispatch({
            type:'getTask',
            payload:{
              code:'workLog',
              pagination:false,
              para:[{key:'Code',values:[query.i]}],
            }
          });
        }
      });
    }
  },
  effects: {
    *getTask({ payload }, { call, put }) {  // eslint-disable-line
      const {data}=yield call(source,payload);
      console.log(data,'ddd222222222222')
      if(data && data.code===0){
        yield put({
          type:'success',
          payload:{
            data:data.data,
          }
        })
      }
    },
    *insertWork({payload}, {call, put}) {
      yield call(insertWork,payload);  //发表工作日志

    },

    *start({payload},{call,put}){
      const {data} = yield call(start,payload);  //增加人员
      // console.log(data,'搜索sssssssssssssssssss')
      // if (!empty(data)) {
      //   yield put({
      //     type: 'success',
      //     payload: {
      //       data: data
      //     }
      //   })
      // }
    },
    //删除人员
    *personDelete({payload},{call,put}){
      const {data} = yield call(personDelete,payload);  //增加人员
      let data1=data.code;
      if(data1==1){
        WitNotification("操作提示","删除失败！！","exclamation-circle-o","red")
      }
      if (data1=='0') {
        WitNotification("操作提示","删除成功！","exclamation-circle-o","blue")
        yield put({
          type: 'success',
        })
      }
    }
  },
  reducers: {
    fetch(state, action) {
      return {...state, ...action.payload};
    },
    success(state, action) {
      return {...state, ...action.payload};
    }
  }
}
